'use client';

import { useEffect } from 'react';

export default function PWARegister() {
  useEffect(() => {
    // 仅在浏览器环境和生产环境注册Service Worker
    if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
      // 本地测试也启用PWA
      // if (process.env.NODE_ENV === 'production') {
        window.addEventListener('load', () => {
          navigator.serviceWorker.register('/sw.js')
            .then(registration => {
              console.log('Service Worker 注册成功:', registration);
            })
            .catch(error => {
              console.error('Service Worker 注册失败:', error);
            });
        });
      // }
    }
  }, []);

  return null;
} 